import java.nio.ByteBuffer;
import java.util.Date;

import org.jnetpcap.Pcap;
import org.jnetpcap.PcapHandler;
import org.jnetpcap.PcapPktBuffer;
import org.jnetpcap.PcapPktHdr;
import org.jnetstream.capture.Captures;
import org.jnetstream.capture.LiveCapture;


public class NetworkAdapter implements PcapHandler<String>, Runnable {


	

	
	private Pcap pcap;

	
	public NetworkAdapter(Pcap pcap) {
		this.pcap = pcap;
	}
	
	
	
	
	@Override
	public void run() {
		while (true) {
			PcapPktHdr pkt_header = new PcapPktHdr();
			PcapPktBuffer buffer = new PcapPktBuffer();
			if (pcap.nextEx(pkt_header, buffer) == 1) {
				new Thread(new PacketAnalyzer(pkt_header, buffer)).start();
			}
		}
		
	}

	@Override
	public void nextPacket(String user, long seconds, int useconds, int caplen,
			int len, ByteBuffer buffer) {
		Date timestamp = new Date(seconds * 1000);
		System.out.printf("%s caplen=%-4d len=%-4d %s\n", timestamp, caplen, len, user);
		
	}
	
	private void parse(PcapPktHdr pkt_header, PcapPktBuffer buffer) {
		// TODO Auto-generated method stub
		
	}

}
